<?php
include("../lib/item.lib");
include("../lib/db.lib");
include("../lib/std.lib");
$cat_id=param("cat_id");
$shop_id=param("shop_id");
$title=cat_get_title($shop_id,$cat_id);

$base_url="http://xys.3322.org/";

$num=param("num");
if($num<1) { $num=10; }

$current_start=param("next_start");
if($pre){
	$current_start=param("pre_start");
}

$current_start=max(0,$current_start);
$next_start=$current_start+$num;
$pre_start=max(0,$current_start-$num);

$key=param('key');
$S_index=param('index');

?>
<html>



<HTML><HEAD><TITLE>Catalog display</TITLE>
<META NAME='KEYWORDS' CONTENT=''/>
<LINK REL="stylesheet" HREF="wiki.css">
<META NAME="description" content="">
<meta http-equiv="Content-Style-Type"  content="text/css">
<meta http-equiv="imagetoolbar" content="no" />
<meta http-equiv="Content-Type"   content="text/html; charset=GB2312">
 <title>My Google AJAX Search API Application</title>
  <link href="http://www.google.com/uds/css/gsearch.css" type="text/css" rel="stylesheet"/>
<script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key=ABQIAAAA3ve8phvqNfrm5tbWCXz3KhRyW-rwrmqOrznv6dfOU47qi8Lw7xToR7GvwkPEewk7hFrwQwBzu4wM_w" type="text/javascript"></script>  <script type="text/javascript">
    //<![CDATA[

function changeAction(){
       var x=document.getElementById("myform");
		var keyword=x.key.value;
		alert(keyword);
		OnLoad();
		return false;
	}

    function OnLoad() {
      new RawSearchControl();
    }

    /**
     * The RawSearchControl demonstrates how to use Searcher Objects
     * outside of the standard GSearchControl. This includes calling
     * searcher .execute() methods, reacting to search completions,
     * and if you had previously disabled html generation, how to generate
     * an html representation of the result.
     */
    function RawSearchControl() {
	  // Create a search control

      // site restricted web search with custom label
      // and class suffix

      var siteSearch = new GwebSearch();

      siteSearch.setUserDefinedLabel("xys.org");
      siteSearch.setUserDefinedClassSuffix("siteSearch");
      siteSearch.setSiteRestriction("<? echo ${base_url};?>xys");
	  siteSearch.setResultSetSize(GSearch.LARGE_RESULTSET);


     siteSearch.setSearchCompleteCallback(this,
                                         RawSearchControl.prototype.searchComplete,
                                         [siteSearch]
                                         );
	 siteSearch.execute("<?php echo param("key");?>");

   }

	 RawSearchControl.prototype.searchComplete = function(siteSearch) {
		
      var i=0;
 	  document.getElementById("ReUrl").innerHTML = siteSearch.results.length;
	  for(i=0;i<siteSearch.results.length;i++)
	  {
		var re=siteSearch.results[i];
 	  document.getElementById("list").innerHTML += "\n"+
      re.unescapedUrl + "&nbsp; <b>Select this one:</b> <input type=checkbox name=product_"+  String(i) + " value=\" " + re.unescapedUrl + "\">"+ 
"<br>\n <input type=text size=50 name=title_"+ String(i) + " value=\" " +  re.titleNoFormatting + "\"><br>\n <pre>\n"+ re.content + "\n</pre><br>\n<a target=\"_blank\" href=" + re.cacheUrl + ">Cache</a> &nbsp; <a target=\"_blank\" href=" + re.url + ">See it</a>" + "<hr>" ;
	  }
   	siteSearch.clearResults();

	}

//    function DummyClipSearchResult(result) {}

    GSearch.setOnLoadCallback(OnLoad);
 

    //]]>
    </script>
  </head>
<body>
<br>
<h2>
<?php
echo " Select items to add to:".$title;
?>
</h2>
<h1>
Aha! Let's do search!</h1>

<form action="" method="post"  id="myform">
Key word: <input type="text" name="key" value="<?php echo $key;?>" size=20>
<input type="hidden" name="cat_id" value="<?php echo $cat_id;?>">
<input  type="submit" value="Do search" >     
</form>


<form action="d_add_product.php" method="post">
<input type="hidden" name="cat_id" value="<?php echo $cat_id;?>">
<input type="hidden" name="num" value="10">
<div id="ReUrl"></div>
<hr>
<div id="list"></div>
<br>
<input type="submit" value="Add selected item to catalog">
</form>

<br>
<?php
	require("copyright.php");
?>
</body>
</html>
